import { BaseWindow } from "../../../component/window/BaseWindow";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { BaseItem } from "../common/BaseItem";
import { ItemData } from "../../resource/info/ItemData";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { ColorConfig } from "../../resource/ColorConfig";
import { Cache } from "../../cache/Cache";
import { ENpcEffect } from "../../../../Message/Public/ENpcEffect";
import { FlyFootBmp } from "../mapUI/flyFoot/FlyFootBmp";
import { AIManager } from "../../scene/ai/AIManager";
import { AIType } from "../../scene/ai/AIType";
import { UpgradeVo } from "./data/UpgradeVo";
import { MsgManager } from "../../manager/MsgManager";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { ECategory } from "../../../../Message/Public/ECategory";
import { EProp } from "../../../../Message/Public/EProp";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { NetDispatcher } from "../../../mvc/core/NetDispatcher";
import { ServerCommand } from "../../mvc/ServerCommand";
import { GButton } from "../../../../com/mui/controls/GButton";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
import { TaskTargetInfo } from "../../model/TaskTargetInfo";
type int = number;
//class ToolStrengthenWindow
    
    export  class ToolStrengthenWindow extends BaseWindow
    {
        constructor()
        {
            super();
            if (ToolStrengthenWindow._instance) 
            {
                throw new Error("ToolStrengthenWindow单例");
            }
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this.setSize(300, 230);
            this.titleHeight = 28;
            this.title = Language.getString(27655);
            var loc1=ObjCreate.createBg(19, 40, 130, 150, this);
            var loc2=ObjCreate.createBg(152, 40, 130, 150, this);
            this._lBgOne = ObjCreate.createBg(52, 70, 64, 64, this, ImagesConst.PackItemBg);
            this._lBgTwo = ObjCreate.createBg(186, 70, 64, 64, this, ImagesConst.PackItemBg);
            this._itemOne = new BaseItem();
            this._itemOne.itemData = new ItemData(14145400);
            this._itemOne.isDragAble = false;
            ObjCreate.setObjAttri(this._itemOne, 55, 73, 59, 59, this);
            this._itemTwo = new BaseItem();
            this._itemTwo.itemData = new ItemData(14145500);
            this._itemTwo.isDragAble = false;
            ObjCreate.setObjAttri(this._itemTwo, 188, 73, 59, 59, this);
            this._itemOneNum = ObjCreate.createTextField("", 98, 117, 20, 20, this, GlobalStyle.textFormatWhite);
            this._itemTwoNum = ObjCreate.createTextField("", 232, 117, 20, 20, this, GlobalStyle.textFormatWhite);
            var loc3=ObjCreate.createGTextField("", 50, 48, 80, 20, this);
            loc3.htmlText = HTMLUtil.addColor(this._itemOne.itemData.name, ColorConfig.instance.getItemColorString(this._itemOne.itemData.color));
            var loc4;
            (loc4 = ObjCreate.createGTextField("", 185, 48, 80, 20, this)).htmlText = HTMLUtil.addColor(this._itemTwo.itemData.name, ColorConfig.instance.getItemColorString(this._itemTwo.itemData.color));
            var loc5=ObjCreate.createGTextField("提升1000经验", 45, 138, 80, 20, this);
            var loc6=ObjCreate.createGTextField("提升3000经验", 180, 138, 80, 20, this);
            this._itemOneBtn = ObjCreate.createGButton("使用", 45, 158, 80, 28, this);
            this._itemOneBtn.name = "itemOne";
            this._itemOneBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onItemClickHandler);
            this._itemTwoBtn = ObjCreate.createGButton("使用", 180, 158, 80, 28, this);
            this._itemTwoBtn.name = "itemTwo";
            this._itemTwoBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onItemClickHandler);
            this._npcTarget = Cache.instance.scene.getNpcByEffect(ENpcEffect._ENpcEffecActiveExchange);
            var loc7=new FlyFootBmp();
            ObjCreate.setObjAttri(loc7, 180, 200, -1, -1, this);
            loc7.addEventListener(flash.events.MouseEvent.CLICK, this.onFlyFootClickHandler);
            var loc8;
            (loc8 = ObjCreate.createTextField("", 59, 202, 140, 20, this, GlobalStyle.textFormatWhite)).addEventListener(flash.events.TextEvent.LINK, this.onExchangeLinkHandler);
            loc8.htmlText = Language.getStringByParam(27688, this._npcTarget.name);
            return;
        }

        /* internal  */onExchangeLinkHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            if (this._npcTarget) 
            {
                this.hide();
                AIManager.onAutoPathAIControl(this._npcTarget);
            }
            return;
        }

        /* internal  */onFlyFootClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._npcTarget) 
            {
                this.hide();
                AIManager.onAIControl(this._npcTarget, AIType.AI_Convey);
            }
            return;
        }

        /* internal  */onItemClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (arg1.target.name != "itemOne") 
            {
                if (arg1.target.name == "itemTwo") 
                {
                    this._curSelectItem = this._itemTwo.itemData;
                }
            }
            else 
            {
                this._curSelectItem = this._itemOne.itemData;
            }
            this.onPromoteHandler();
            return;
        }

        /* internal  */onPromoteHandler(): void
        {
            var loc1=null;
            var loc2=null;
            if (this._curSelectWeapon) 
            {
                loc1 = new UpgradeVo();
                loc2 = Cache.instance.pack.backPackCache.getUidListByType(this._curSelectItem.category, this._curSelectItem.type, this._curSelectItem.effect);
                if (loc2.length < 1) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(27683));
                    return;
                }
                loc1.opType = 2;
                loc1.materials = [loc2[0]];
                loc1.posType = this._curSelectWeapon.posType;
                loc1.amuletUid = this._curSelectWeapon.uid;
                loc1.isUpgradeByTool = true;
                Dispatcher.dispatchEvent(new DataEvent(EventName.MagicWeaponUpgrade, {"vo": loc1}));
            }
            return;
        }

        /* internal  */setBtn(arg1: Object=null): void
        {
            var loc1=Cache.instance.pack.backPackCache.getItemCountByCategoryAndType(ECategory._ECategoryProp, EProp._EPropAmuletActiveItem, 1000);
            var loc2=Cache.instance.pack.backPackCache.getItemCountByCategoryAndType(ECategory._ECategoryProp, EProp._EPropAmuletActiveItem, 3000);
            if (loc1 <= 0) 
            {
                this._itemOneNum.text = "";
                this._itemOne.filters = [FilterConst.colorFilter2];
                this._itemOneBtn.filters = [FilterConst.colorFilter2];
                this._itemOneBtn.enabled = false;
            }
            else 
            {
                this._itemOneNum.text = loc1.toString();
                this._itemOne.filters = [];
                this._itemOneBtn.filters = [];
                this._itemOneBtn.enabled = true;
            }
            if (loc2 <= 0) 
            {
                this._itemTwoNum.text = "";
                this._itemTwo.filters = [FilterConst.colorFilter2];
                this._itemTwoBtn.filters = [FilterConst.colorFilter2];
                this._itemTwoBtn.enabled = false;
            }
            else 
            {
                this._itemTwoNum.text = loc2.toString();
                this._itemTwo.filters = [];
                this._itemTwoBtn.filters = [];
                this._itemTwoBtn.enabled = true;
            }
            return;
        }

        public showWindow(arg1: ItemData): void
        {
            this._curSelectWeapon = arg1;
            this.setBtn();
            this.show();
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            NetDispatcher.addCmdListener(ServerCommand.BackpackDataChange, this.setBtn);
            NetDispatcher.addCmdListener(ServerCommand.BackPackItemsChange, this.setBtn);
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            NetDispatcher.removeCmdListener(ServerCommand.BackpackDataChange, this.setBtn);
            NetDispatcher.removeCmdListener(ServerCommand.BackPackItemsChange, this.setBtn);
            return;
        }

        public static get instance(): ToolStrengthenWindow
        {
            if (ToolStrengthenWindow._instance == null) 
            {
                ToolStrengthenWindow._instance = new ToolStrengthenWindow();
            }
            return ToolStrengthenWindow._instance;
        }

        /* internal */ /* var */_itemOne: BaseItem;

        /* internal */ /* var */_itemTwo: BaseItem;

        /* internal */ /* var */_itemOneBtn: GButton;

        /* internal */ /* var */_itemTwoBtn: GButton;

        /* internal */ /* var */_itemOneNum: Object /* flash.text.TextField */;

        /* internal */ /* var */_itemTwoNum: Object /* flash.text.TextField */;

        /* internal */ /* var */_curSelectItem: ItemData;

        /* internal */ /* var */_lBgOne: ScaleBitmap;

        /* internal */ /* var */_lBgTwo: ScaleBitmap;

        /* internal */ /* var */_curSelectWeapon: ItemData;

        /* internal */ /* var */_npcTarget: TaskTargetInfo;

        /* internal */ static /* var */_instance: ToolStrengthenWindow;
    }
